#include<iostream>
#include<glut.h>

#include"TextInstance.h"

void DisplayFunction();

TextInstance text;

void SpecialKeyFunction(int key , int x , int y)
{
}

void KeyboardFunction(unsigned char key , int x , int y)
{
	if(key >= ' ' && key <= '~')
	{
		text.CharEvent(key);
	}
	else
	{
		switch(key)
		{
		}
	}
	DisplayFunction();
}

void DisplayFunction()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();
	gluLookAt(0 , 0 , 5 , 0 , 0 , 0 , 0 , 1 , 0);

	text.display();

	glFlush();
	glutSwapBuffers();
}

void ReshapeFunction(int w, int h)
{
	glViewport(0, 0, w, h);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0 , w , -h , 0 , -99999 , 99999);
	glMatrixMode(GL_MODELVIEW);
}

void main(int argc , char** argv)
{
	glutInit(&argc , argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
	glutInitWindowSize(800 , 600);
	glutCreateWindow("Text Editor");
	glClearColor(1.0 , 1.0 , 1.0 , 0.0);

	glutReshapeFunc(ReshapeFunction);
	glutDisplayFunc(DisplayFunction);
	glutKeyboardFunc(KeyboardFunction);
	glutSpecialFunc(SpecialKeyFunction);

	glutMainLoop();
}